<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='评论管理',active='sensitiveWords'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">敏感词管理</h4>
                    </div>
                    <div class="col-md-12">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>敏感词</th>
                                <th>替换词</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <th:block th:each="sw : ${sensitiveWords.list}">
                                <tr th:attr="id=${sw.id}">
                                    <td th:text="${sw.sensitiveWord}"></td>
                                    <td th:text="${sw.replaceWord}"></td>
                                    <td th:text="${commons.fmtdate(sw.created, 'yyyy-MM-dd HH:mm:ss')}"></td>
                                    <td>
                                        <a href="javascript:void(0)" th:onclick="'del('+${sw.id}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i
                                                class="fa fa-trash-o"></i> <span>删除</span></a>
                                    </td>
                                </tr>
                            </th:block>
                            </tbody>
                        </table>
                        <div th:replace="comm/macros :: pageAdminNav(${sensitiveWords})"></div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-12" style="padding: 20px;">
                            <div class="panel panel-primary">
                                <div class="panel-heading"><h3 class="panel-title">添加敏感词，默认替换为3个*</h3></div>
                                <div class="panel-body">

                                    <form id="addForm" class="form-inline" role="form" novalidate="novalidate">

                                        <div class="form-group">
                                            <label class="sr-only">敏感词</label>
                                            <input type="text" id="sensitiveWord" name="sensitiveWord" class="form-control" placeholder="请输入替换词"
                                                   required="required" aria-required="true"/>
                                        </div>

                                        <div class="form-group">
                                            <label class="sr-only">替代词</label>
                                            <input type="text" id="replaceWord" name="replaceWord" class="form-control" placeholder="请输入替换词" value="***" required="required"
                                                   aria-required="true"/>
                                        </div>

                                        <button type="submit" class="btn btn-success waves-effect waves-light m-l-10">保存</button>
                                    </form>
                                </div> <!-- panel-body -->
                            </div> <!-- panel -->
                        </div> <!-- col -->

                    </div>
                    
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/localization/messages_zh.min.js"></script>

<script type="text/javascript">
    /*<![CDATA[*/
    var tale = new $.tale();

    $('#addForm').validate({
        submitHandler: function (form) {
            var params = $("#addForm").serialize();
            tale.post({
                url : ctxPath+'admin/sensitiveWords/save',
                data: params,
                success: function (result) {
                    $('#linkForm input').val('');
                    if(result && result.success){
                        tale.alertOkAndReload('保存成功');
                    } else {
                        tale.alertError(result.msg || '保存失败');
                    }
                }
            });
        }
    });

    function del(id) {
        tale.alertConfirm({
            title: '确定删除该敏感词吗?',
            then: function () {
                tale.post({
                    url: ctxPath+'admin/sensitiveWords/delete',
                    data: {id: id},
                    success: function (result) {
                        if (result && result.success) {
                            tale.alertOkAndReload('删除成功');
                        } else {
                            tale.alertError(result.msg || '删除失败');
                        }
                    }
                });
            }
        });
    }

    /*]]>*/
</script>
</body>
</html>